﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FineUIPro;
using CanDoo.Admin.Core.Models;

namespace CanDoo.Oil.WebHost.Code
{
    public static class StaticListBind
    {
        public static void BindChinaArea_Province(IEnumerable<ListItem> provinceList, DropDownList DDL, bool Required = false)
        {
            DDL.DataTextField = "Text";
            DDL.DataValueField = "Value";
            DDL.DataSource = provinceList;
            DDL.DataBind();

            FineUIPro.ListItem First = new FineUIPro.ListItem();
            First.Text = "--请选择--";
            First.Value = 0L.ToString();
            DDL.Items.Insert(0, First);

            if (Required)
            {
                DDL.Required = true;
                DDL.ShowRedStar = true;
                DDL.CompareType = CompareType.String;
                DDL.CompareOperator = Operator.NotEqual;
                DDL.CompareValue = 0L.ToString();
            }
            DDL.SelectedIndex = 0;
        }

        public static void BindChinaArea_Child(IEnumerable<ListItem> childList, DropDownList DDL, int Level, string ParentCode, bool Required = false)
        {
            DDL.Items.Clear();
            if (ParentCode == "" || ParentCode == 0L.ToString())
            {
                string emptyText = "";
                if (Level == 2)
                    emptyText = "省份";
                else if (Level == 3)
                    emptyText = "城市";
                else if (Level == 4)
                    emptyText = "区";

                FineUIPro.ListItem Empty = new FineUIPro.ListItem();
                Empty.Text = "--请选择" + emptyText + "--";
                Empty.Value = 0L.ToString();
                DDL.Items.Insert(0, Empty);
            }
            else
            {
                //var childList = q.Where(p => p.ParentCode == ParentCode).OrderBy(p => p.Code);

                DDL.DataTextField = "Name";
                DDL.DataValueField = "Code";
                DDL.DataSource = childList;
                DDL.DataBind();

                FineUIPro.ListItem First = new FineUIPro.ListItem();
                First.Text = "--请选择--";
                First.Value = 0L.ToString();
                DDL.Items.Insert(0, First);
            }

            if (Required)
            {
                DDL.Required = true;
                DDL.ShowRedStar = true;
                DDL.CompareType = CompareType.String;
                DDL.CompareOperator = Operator.NotEqual;
                DDL.CompareValue = 0L.ToString();
            }
            DDL.SelectedIndex = 0;
        }


        public static void BindSex(FineUIPro.RadioButtonList RBL, bool Required = false)
        {
            FineUIPro.RadioItem item = new FineUIPro.RadioItem();
            item.Text = "男";
            item.Value = "1";
            RBL.Items.Add(item);

            item = new FineUIPro.RadioItem();
            item.Text = "女";
            item.Value = "2";
            RBL.Items.Add(item);

            if (Required)
            {
                RBL.Required = true;
                RBL.ShowRedStar = true;
            }
        }


        public static void BindEnable(FineUIPro.RadioButtonList RBL, bool Required = false)
        {
            FineUIPro.RadioItem item = new FineUIPro.RadioItem();
            item.Text = "启用";
            item.Value = "True";
            RBL.Items.Add(item);

            item = new FineUIPro.RadioItem();
            item.Text = "禁用";
            item.Value = "False";
            RBL.Items.Add(item);

            if (Required)
            {
                RBL.Required = true;
                RBL.ShowRedStar = true;
            }
        }




        public static void BindWhetherOrNot(FineUIPro.RadioButtonList RBL, bool Required = false)
        {
            FineUIPro.RadioItem item = new FineUIPro.RadioItem();
            item.Text = "是";
            item.Value = "True";
            RBL.Items.Add(item);

            item = new FineUIPro.RadioItem();
            item.Text = "否";
            item.Value = "False";
            RBL.Items.Add(item);

            if (Required)
            {
                RBL.Required = true;
                RBL.ShowRedStar = true;
            }
        }
    }
}